package cn.wolfcode.shop.cloud.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    public static final int SUCCESS_CODE = 200;
    public static final String SUCCESS_MESSAGE = "操作成功";
    public static final int DEFAULT_ERROR_CODE = 500;
    public static final String DEFAULT_ERROR_MSG = "系统异常";

    private int code;
    private String msg;
    private T data;

    public static <T>Result<T> success(T data){
        return new Result<>(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }

    public static <T>Result<T> success(String msg,T data){
        return new Result<>(SUCCESS_CODE,msg,data);
    }

    public static Result error(CodeMsg codeMsg){
        return new Result(codeMsg.getCode(),codeMsg.getMsg(),null);
    }

    public static Result defaultError(){
        return new Result(DEFAULT_ERROR_CODE,DEFAULT_ERROR_MSG,null);
    }
}
